package com.want.evenchat.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.want.evenchat.Application;

/**
 * Created by Want on 2018/5/6.
 */

public class SpUtils {

    public static final String IS_NEW_INVITE = "is_new_invite";//新的邀请标记
    private static SpUtils instance = new SpUtils();

    private static SharedPreferences even_chat;

    private SpUtils() {

    }

    //单例模式
    public static SpUtils getInstance(){

//        context.getSharedPreferences();
        if (even_chat == null){
            even_chat = Application.getGlobalApplication().getSharedPreferences("Even_chat", Context.MODE_PRIVATE);
        }

        return instance;
    }

    //保存
    public void save(String key , Object value){
        if (value instanceof String){
            even_chat.edit().putString(key, (String) value).commit();
        } else if (value instanceof Boolean) {
            even_chat.edit().putBoolean(key, (Boolean) value).commit();
        }else if (value instanceof Integer){
            even_chat.edit().putInt(key, (Integer) value).commit();
        }
    }

    //获取数据的方法
    public String getString(String key , String defValue){
        return even_chat.getString(key,defValue);
    }

    public Boolean getBoolean(String key , Boolean defValue){
        return even_chat.getBoolean(key,defValue);
    }

    public int getInt(String key , int defValue){
        return even_chat.getInt(key,defValue);
    }

}
